// Define a new module for our app. The array holds the names of dependencies if any.
var app = angular.module("instantSearch", []);

// Create the instant search filter

app.filter('searchFor', function(){

	// All filters must return a function. The first parameter
	// is the data that is to be filtered, and the second is an
	// argument that may be passed with a colon (searchFor:searchString)

	return function(arr, searchString){

		if(!searchString){
			return arr;
		}

		var result = [];

		searchString = searchString.toLowerCase();

		// Using the forEach helper method to loop through the array
		angular.forEach(arr, function(item){
			if(item.title.toLowerCase().indexOf(searchString)!== -1 || item.url.toLowerCase().indexOf(searchString)!== -1)
         {result.push(item);}
		});
		return result;
      };
});

// The controller

function InstantSearchController($scope){

	// The data model. These items would normally be requested via AJAX,
	// but are hardcoded here for simplicity. See the next example for
	// tips on using AJAX.

	$scope.items = [
		{
			url: 'Pisang',
			title: 'مَوْزَةٌ',
			image: 'http://i.imgur.com/KR5KYw2.jpg'
		},
		{
			url: 'Oren',
			title: 'بُرْتُقَالَة',
			image: 'http://i.imgur.com/F1EEWYl.jpg'
		},
		{
			url: 'Pear',
			title: 'كُمَّثْرَى atau إجَّاص',
			image: 'http://i.imgur.com/0ViPrwq.jpg'
		},
		{
			url: 'Nenas',
			title: 'أَنَانَاس',
			image: 'http://i.imgur.com/zRjFalN.jpg'
		},
		{
			url: 'Tembikai',
			title: 'بِطِّيخٌ',
			image: 'http://i.imgur.com/Na8m8CJ.jpg'
		},      
      	{
			url: 'Epal',
			title: 'تُفَّاحَة',
			image: 'http://i.imgur.com/B7Q74lq.jpg'
		}
	];

}
